<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>维护结清费用项</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div id="settle_fee" class="sq-grid"></div>
</div>


<script type="text/javascript">
    var basePath = '<%=path%>';
    var paySchId = '${paySchId}';
    var pInstId = '${pInstId}';
    var g = null;
    $(function () {

        g = $("#settle_fee").ligerGrid({
            url: basePath + '/settlement/fee/initSettleFeeList.do?paySchId=' + paySchId,
            method: 'get',
            columns: [
                {display: 'ID', name: 'id', width: 2, hide: true, align: 'center', enabledSort: false},
                {display: '费用项名称', name: 'feeTypCdNm', minWidth: 80, align: 'center', enabledSort: false},
                {display: '费用金额', name: 'feeAmt', minWidth: 80, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var amt = renderAmt(rowdata, rowindex, value);
                        var show = "<span>" + amt + "</span>";
                        if (rowdata.capFlow == ProjectConstant.CODE_PRJ_QUAT_CASH_FLOW_OUT) {
                            show = "<span style='color:red'>-" + amt + "</span>";
                        }
                        return show;
                    }
                },
                {
                    display: '操作',
                    minWidth: 100,
                    render: function (rowdata, rowindex, value) {
                        if (rowdata.isSysDef == 1) {
                            return '<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="系统内置结清费用，不允许操作！"></span>';
                        }
                        var other= "";
                        other+='<a class="sq-button-hasicon" href="javascript:;" onclick="addOrEditSettleFee(';
                        other+="'"+rowindex+"'";
                        other+=")\"><i class=\"sqBtnIco_4\"></i>"+'修改'+"</a>";
                        //other += " | ";
                        other+='<a class="sq-button-hasicon" href="javascript:;" onclick="removeSettleFee(';
                        other+="'"+rowindex+"'";
                        other+=")\"><i class=\"sqBtnIco_7\"></i>"+'删除'+"</a>";
                        return other;
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            width: '100%',
            height: 360,
            checkbox: false,
            isSingleCheck: true,
            rownumbers: true,
            toolbar: {
                items: [
                    {text: '<span class="sq-button sq-button-hasicon"><i class="sqBtnIco_3"></i>新增</span>',
                        click: function (){
                            addOrEditSettleFee(undefined);
                        }
                    }
                ]
            }
        });

    });

    function addOrEditSettleFee(rowindex) {
        var onOk = function (item, Dialog) {
            if (Dialog.onOk) Dialog.onOk();
        };
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        var title = "", url;
        if (rowindex == undefined) {
            title = "新增结清费用信息";
            url = '/settlement/fee/toAddOrEditPage.do?paySchId=' + paySchId + "&pInstId=" + pInstId;
        } else {
            var rowdata = g.getRow(rowindex);
            title = "编辑结清费用信息";
            url = '/settlement/fee/toAddOrEditPage.do?paySchId=' + paySchId + "&id=" + rowdata.id + "&pInstId=" + pInstId;
        }
        $.ligerDialog.open({
            width: 480,
            height: 300,
            showMax: false,
            title: title,
            url: basePath + url,
            buttons: [{
                text: "保存", type: 'ok', onclick: onOk
            }, {
                text: "关闭", type: 'cancel', onclick: onCancel, cls: 'l-dialog-btn-no'
            }],
            onClose: function() {
                g.reload();
            }
        });
    }

    function removeSettleFee(rowindex) {
        $.ligerDialog.confirm("确定要删除此费用项吗？", function (flag) {
            if (flag == false) return;
            var rowdata = g.getRow(rowindex);
            rowdata.pInstId = pInstId;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: rowdata,
                url: basePath + '/settlement/fee/removeSettleFee.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({
                            content: msg.info, SQ_showButtons: true, SQ_type: "success", SQ_onBtnclick: function () {
                                g.reload();
                            }
                        });
                    } else {
                        UIUtils.alertErrorHold1(msg.info);
                    }
                }
            });
        });
    }


    //格式化为人民币格式
    function renderAmt(rowdata, rowindex, value) {
        if (null !== value && value !== 'undefined' && value !== "") {
            if (typeof Number(value) == 'number') {
                var h = "￥" + FormatMoney((parseFloat(value)).toFixed(2));
                return h;
            }
        }
    }
</script>

</body>
</html>
